<template>
  <div class="app-container" id='subject'>
    <div class="filter-container" style="float: right;">
      <el-input v-model="listQuery.title" clearable class="filter-item" style="width: 200px;" placeholder="请输入专题标题"></el-input>
      <el-input v-model="listQuery.subtitle" clearable class="filter-item" style="width: 200px;" placeholder="请输入专题子标题"></el-input>
      <el-button type="primary" class="filter-item" icon="el-icon-search" @click="handleFilter">查询</el-button>
      <el-button type="primary" class="filter-item" icon="el-icon-edit" @click="handleCreate">添加</el-button>
    </div>
    <el-table :data="tableData" style="width: 100%" border fit highlight-current-row>
      <el-table-column prop="title" align="center" label="专题标题" sortable width="120">
      </el-table-column>
      <el-table-column prop="subtitle" align="center" label="专题子标题" width="200" show-overflow-tooltip>
      </el-table-column>
      <el-table-column prop="picUrl" align="center" label="图片">
        <template slot-scope="scope">
          <img :src="scope.row.picUrl" width="80">
        </template>
      </el-table-column>
      <el-table-column align="center" label="专题详情" prop="content">
          <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="showContent(scope.row.content)">查看</el-button>
          </template>
      </el-table-column>
      <el-table-column prop="price" align="center" label="底价">
      </el-table-column>
      <el-table-column prop="readCount" align="center" label="阅读数量">
      </el-table-column>
      <el-table-column align="center" fixed="right" label="操作" width="200">
        <template slot-scope="scope">
          <el-button @click="handleUpdate(scope.row)" type="primary" size="small">编辑</el-button>
          <el-button @click="handleDelete(scope.row)" type="danger" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />
    <el-dialog :visible.sync="contentDialogVisible" title="专题详情" width="55%">
      <div v-html="contentDetail"/>
    </el-dialog>
  </div>
</template>
<script>
  import Pagination from '@/components/Pagination'
  import {
    listSubject,
    deleteSubject,
  } from '@/api/activity/subject'
  export default {
    name: 'subject',
    components: {
      Pagination
    },
    computed: {
    },
    data() {
      return {
        //查询数据
        listQuery: {
          page: 1,
          limit: 10,
          title: '',
          subtitle: '',
        },
        //总条数
        total: 0,
        //表格数据
        tableData: [],
        //添加或修改模态框状态
        dialogFromVisible: false,
        //打开详情模态框状态
        contentDialogVisible: false,
        //存储详情数据
        contentDetail: '',
      }
    },
    created() {
      // 数据初始化
      this.getList();
    },
    methods: {
      //查询列表
      handleFilter() {
        this.listQuery.page = 1;
        this.getList();
      },
      //获取列表数据接口
      getList() {
        listSubject(this.listQuery).then(res => {
          console.log(res);
          this.tableData = [];
          this.tableData = res.data.data.list;
          this.total = res.data.data.total;
        })
      },
      //进入新增页面
      handleCreate() {
      this.$router.push({path:'/activity/addSubject'})
      },
      //进入修改页面
      handleUpdate(row) {
        this.$router.push({path:'/activity/editSubject',query:{id:row.id}})
      },
      //删除
      handleDelete(row) {
        this.$confirm('此操作将删除该专题，是否继续？','提示',{
          confirmButtonText: '确定',
          concelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteSubject(row).then(res => {
            this.getList();
            this.$notify.success({
              title: '成功',
              message: '删除成功'
            })
          })
        }).catch(() => {
           this.$message({
             type: 'info',
             message: '已取消删除'
           })
        })
      },
      //查看详情
      showContent(content){
         this.contentDetail = content;
         this.contentDialogVisible = true;
      },
    }
  }
</script>
<style>
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

</style>
<style scoped>
</style>
